﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for bzAdminPageAbout
/// </summary>
public abstract class bzAdminPageAbout:System.Web.UI.Page
{
    //----------------------------------------------------------
    private DataRow _SiteOption = null;
    public DataRow SiteOption { get { return _SiteOption; } }

    private DataRow _AdminLang = null;
    public DataRow AdminLang { get { return _AdminLang; } }

    private string _Navigator = "";
    public string Navigator { get { return _Navigator; } set { _Navigator = value; } }

    private string _Act = "";
    public string Act { get { return _Act; } }

    private string _CurrentLang = "VN";
    public string CurrentLang { get { return _CurrentLang; } }

    private string _AboutKey = "";
    public string AboutKey { set { _AboutKey = value; } }

    //---------Check permission
    private bool _CheckPermission = true;
    public bool CheckPermission { set { _CheckPermission = value; } }

    public bool AllowView { get { return this.check(bzCheckAdminUser.View); } }
    public bool AllowEdit { get { return this.check(bzCheckAdminUser.Edit); } }
    private bool check(int Per)
    {
        return bzCheckAdminUser.checkUserPermission(Session["AdminUser"].ToString(), Session["AdminLevel"].ToString(), Session["IP"].ToString(), Session["LoginID"].ToString(), Session["GroupUser"].ToString(), Session["Page"].ToString(), Per);
    }
    //------------------------------

    public void initSiteLang(string sSiteCate, string sSiteNote, string sLangNote)
    {

        if (!Request.Url.AbsoluteUri.Contains(Session["Page"].ToString()))
        {
            Session["Page"] = Request.Url.AbsoluteUri.Split('?')[0];
        }
        Session["Lang"] = bzAdminLang.checkLang(string.IsNullOrEmpty(Request.QueryString["Lang"]) ? Session["Lang"].ToString() : Request.QueryString["Lang"]);
        _Act = string.IsNullOrEmpty(Request.QueryString["Act"]) ? "" : Request.QueryString["Act"];

        _CurrentLang = Session["Lang"].ToString().ToUpper().Trim();
        _SiteOption = new bzSiteOption(sSiteCate, sSiteNote).SiteOption;
        _AdminLang = new bzAdminLang(Session["Lang"].ToString(), sLangNote).AdminLang;
        if (this._CheckPermission && !this.AllowView)
        {
            Response.Redirect(bzStringClass.AlertPermission);
        }
        this.loadAction();
    }
    abstract protected void loadAction();

    //----------------Data
    private bzAbout _BZ = new bzAbout();
    private string getData(string Colunm)
    {
        DataTable dt = _BZ.getRecord(_AboutKey, bzAbout.Enable.Enabled);
        if (dt.Rows.Count > 0)
            return Server.HtmlDecode(dt.Rows[0][Colunm].ToString());
        return "";
    }

    public string getContent(string Lang)
    {
        return this.getData("Content" + Lang);
    }
    public string getDescription(string Lang)
    {
        return this.getData("Description" + Lang);
    }
    public bool updateData(string ContentVN, string ContentEN, string DesVN, string DesEN)
    {
        if (!this.AllowEdit) Response.Redirect(bzStringClass.AlertPermission);
        int i = _BZ.updateRecord(_AboutKey, DesVN, DesEN, ContentVN, ContentEN);
        return (i > 0 ? true : false);
    }


    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

    }
}
